import javax.swing.JOptionPane;

public class ErrorCheck2 {

/***************************************************************************
  * 
 *****************************************************************************/
static int theDay = 0;
	    public static int changeMonth(String month){
	    	int monthNumber = 0;

	        if (month == null) {
	            return monthNumber;
	        }

	        if(month.equals("January")){
	        	monthNumber = 1;
	        }
	        else if(month.equals("February")){
	        	monthNumber = 2;
	        }
	        else if(month.equals("March")){
	        	monthNumber = 3;
	        }else if(month.equals("April")){
	        	monthNumber = 4;
	        }else if(month.equals("May")){
	        	monthNumber = 5;
	        }else if(month.equals("June")){
	        	monthNumber = 6;
	        }else if(month.equals("July")){
	        	monthNumber = 7;
	        }else if(month.equals("August")){
	        	monthNumber = 8;
	        }else if(month.equals("September")){
	        	monthNumber = 9;
	        }else if(month.equals("October")){
	        	monthNumber = 10;
	        }else if(month.equals("November")){
	        	monthNumber = 11;
	        }else if(month.equals("December")){
	        	monthNumber = 12;
	        }

	        return monthNumber;
	    }
	    /**
		    *Error checks to make sure the days will match up with the months so they do not exceed what is physically impossible
		    *it will also check for leap years 
		    * auto corrects the days to match the last date of that month with an error message 
		    */
	    public static void errorCheck(int month, int day, int year, int time){
	    	theDay = day;
	    	//error check for the wrong day
	    	switch (month) {
	    		//checks to see if it is a month with 31 days
            	case 1: case 3: case 5:
            	case 7: case 8: case 10:
            	case 12:
            		//if the user input of days exceeds 31 it will mark it to 31
            		if(day > 31){            			
            			theDay = 31;
            			JOptionPane.showMessageDialog(null, "Invalid Day (" + day + ") for the month numbered " + month + " automatically changed the day to " + theDay);
            		}
                break;
                //the next case will check for months with 30 days
            	case 4: case 6:
            	case 9: case 11:
            			//if the user input exceeds 30 days then it will correct it to 30 days
            		if (day > 30){
            			theDay = 30;
            			JOptionPane.showMessageDialog(null, "Invalid Day (" + day + ") for the month numbered " + month + " automatically changed the day to " + theDay);
            		}
            	break;
                //for February it checks to see if it is a leap year or not by using a module 
            	case 2:
            		if (((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0)){
            			theDay = 29;
            			JOptionPane.showMessageDialog(null, "Invalid Day for the month of February automatically changed the day to " + theDay);
            		}
            		else{
            			theDay = 28;
            			JOptionPane.showMessageDialog(null, "Invalid Day for the month of February automatically changed the day to " + theDay);
            		}
                break;
            default:
                break;
	    	}
	    	//format(year, month, day, time);
	    }
	    /**
		    *Formats the String date to the correct form for the ics file. It adjust the month, day and time to the correct
		    *amount of 0 
		    * @return the date final format
		    */
	    public static String format(int year, int month, int day, int time){
	    	String date = year + "" + String.format("%02d", month) + "" 
	    + String.format("%02d", day) + "T" + String.format("%04d", time) + "00Z";
	    	//System.out.println(date);
	    	return date;
	    }
}
